package com.dms.controller;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.dms.entity.User;
import com.dms.service.UserService;

@Controller
@RequestMapping(value="/dms.web")
public class MyqzController {
	@Autowired
	@Qualifier("userService")
	private UserService userService;
	
	@RequestMapping(value="/")
	 public String to_index(){
		// 跳转到大赛主页面
		return "myqz/index";
	}
	
	@RequestMapping(value="/reginster")
	 public ModelAndView reginster(@Validated User user, Model model){
		ModelAndView mv=new ModelAndView("myqz/reginsterUser");
		// 参赛注册
		System.out.println(user);
		user.setStudent_num(user.getUsername());
		user.setRole(2);
		userService.incertUser(user);
		//设置注册成功信息
		model.addAttribute("succesfulmsg","报名成功，账号："+user.getStudent_num()+" 密码：123456 请及时登陆系统修改信息");
		return mv;
	}
	
	@RequestMapping(value="/to_reginster")
	 public String to_reginster(){
		// 跳转到大赛参赛页面
		return "myqz/reginsterUser";
	}
	@RequestMapping(value="/userlist")
	 public ModelAndView userlist(Model model){
		ModelAndView mav;
		mav = new ModelAndView("myqz/users");  
		//查表
		List<User> list=userService.findAllUser();
		model.addAttribute("list", list);
		// 跳转到大赛报名名单
		return mav;
	}
	@RequestMapping(value = "/android")
	public String getandroid() {
		// 测试比赛-移动测试
		return "myqz/android";
	}

	@RequestMapping(value = "/web")
	public String getweb() {
		// 测试比赛-WEB测试
		return "myqz/web";
	}
}
